package com.yizhe.service.impl;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.taobao.api.ApiException;
import com.taobao.api.DefaultTaobaoClient;
import com.taobao.api.TaobaoClient;
import com.taobao.api.request.TbkItemGetRequest;
import com.taobao.api.response.TbkItemGetResponse;
import com.yizhe.domain.vo.TbkQueryVO;
import com.yizhe.service.ProductService;

@Service
public class ProductServiceImpl implements ProductService {

	@SuppressWarnings("static-access")
	@Override
	public JSONObject getTbkItems(TbkQueryVO tbkQueryVO) throws ApiException {
		TaobaoClient client = new DefaultTaobaoClient("http://gw.api.taobao.com/router/rest", "23467780", "49568015efce89fdebcaf2dff10aea4c");
		TbkItemGetRequest req = new TbkItemGetRequest();
		JSONObject jsonObject = new JSONObject();
		req.setFields("num_iid,title,pict_url,small_images,reserve_price,zk_final_price,user_type,provcity,item_url,seller_id,volume,nick");
		req.setQ(tbkQueryVO.getQ());
		req.setCat(tbkQueryVO.getCat());
		req.setItemloc(tbkQueryVO.getItemloc());
		req.setSort(tbkQueryVO.getSort());
		req.setIsTmall(tbkQueryVO.getIs_tmall());
		req.setIsOverseas(tbkQueryVO.getIs_overseas());
		req.setStartPrice(tbkQueryVO.getStart_price());
		req.setEndPrice(tbkQueryVO.getEnd_price());
		req.setStartTkRate(tbkQueryVO.getStart_tk_rate());
		req.setEndTkRate(tbkQueryVO.getEnd_tk_rate());
		req.setPlatform(tbkQueryVO.getPlatform());
		req.setPageNo(tbkQueryVO.getPage_no());
		req.setPageSize(tbkQueryVO.getPage_size());
		TbkItemGetResponse rsp = client.execute(req);
		return jsonObject.parseObject(rsp.getBody());
	}

}
